<template>
	
	<view class="container">
		
		 <uni-list :border="true">
		 	<uni-list-chat
			:avatar-circle="true"
			v-for="(item, index) in dataList" :key="index" 
			:title="item.ResultType" :note="item.Result" :avatar="item.ImageURL" :time="item.CreateTime"
			@click="info(index)" :clickable="true" >
			 </uni-list-chat>
			 
<!-- 			 <uni-list-item
			 v-for="(item, index) in dataList" :key="index" 
			 :title="item.Result" :note="item.CreateTime" :thumb="item.ImageURL" :show-arrow="true"
			 thumb-size="lg" rightText="查看详情" @click="info(index)" :clickable="true">
			  </uni-list-item> -->
		</uni-list>
		<uni-load-more 
		iconType="auto" :status="status"  color="#007AFF"
		:content-text="contentText" @clickLoadMore="loadMore">
		</uni-load-more>
		</view>
</template>

<script>
import { convTime } from '../../common/conv';
	export default{
		data(){
			return{
				dataList:[],
				contentText: {
				contentdown: '查看更多',
				contentrefresh: '加载中',
				contentnomore: '没喽~'
				},
				page:1,
				pageSize:10,
				status: 'more',
			}
		},
		onLoad() {
			let tempList = []
			this.loadPage()

		},
	//上拉加载
		onReachBottom(){
			if (this.status == 'noMore'){
				return;
			}
			this.page ++;
			this.loadPage();

		},
		//下拉刷新
		onPullDownRefresh(){
			this.clearPage()
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
			this.loadPage()

		},
		methods:{
			info(id){
				// uni.showToast({
				// 	title:"点击了"+id
				// })
				console.log(this.dataList[id])
				uni.navigateTo({
					url:"/pages/my/historyinfo?info="+encodeURIComponent(JSON.stringify(this.dataList[id]))
				})
				
			},
			loadMore(e){
				if (this.status == 'noMore'){
					return;
				}
				this.page ++;
				console.log(this.page)
				this.loadPage();
			},
			loadPage(){
				uni.request({
					url:"app/history/page",
					method:"GET",
					data:{
						page:this.page,
						page_size:this.pageSize
					},
					header:{'Authorization':uni.getStorageSync('token')},
					success:(res)=> {
						console.log(res)
						// 第一次加载
						if(this.dataList.length == 0){
							this.status = 'more'
							for(let i = 0;i < res.data.data.His.length;i++){
								res.data.data.His[i].CreateTime = convTime(res.data.data.His[i].CreateTime)
							}
							
							this.dataList = this.dataList.concat(res.data.data.His)
							if(this.dataList.length == res.data.data.Total){
								this.status = 'noMore'
								return
							}
						}else{
							if(res.data.data.His.length == 0 && res.data.data.Total == 0){
								this.status = 'noMore'
								return
							}else{
								this.status = 'more'
								for(let i = 0;i < res.data.data.His.length;i++){
									res.data.data.His[i].CreateTime = convTime(res.data.data.His[i].CreateTime)
								}
								this.dataList = this.dataList.concat(res.data.data.His)
							}
						}
					}
				})
			},
			clearPage(){
				this.page = 1
				this.dataList = []
			}
		}
	}
</script>

<style>
</style>